<?php
function login($userid,$password) {
	global $resourceString, $dbname, $db, $db_selected;
	
	// Check obvious stuff
    if (empty($userid) || empty($password)) {
		$error = 1;
		$message = "You must enter a User Name and Password.";
	}
	if (empty($error)) {
		// Check against dbase
		$sql = "SELECT * from transLogin WHERE Userid = '$userid' AND Password = '$password'";
		$result = mysql_db_query($dbname,$sql);
		$numRows = mysql_num_rows($result);
		if (empty($numRows)) {
		    $error = 1;
		    $message = "Sorry! I can't find your login information. Please try again.";
		}
	}
	if (empty($error)) {
	    // Login and populate session and cookies
	    $row = mysql_fetch_assoc($result);

	    // Session vars
	    $_SESSION['UID']          = $row[UID];
	    $_SESSION['userid']       = $row[Userid];
	    $_SESSION['userFullName'] = $row[FullName];
	    $_SESSION['userLevel']    = $row[AdminLevel];
	    $_SESSION['logged']       = 1;
			    
	    $error = 0;
	    
	    $returnString = $row[UID].'|'.$row[FullName].'|1';
	}
		
	return $error.'|'.$message.'|'.$returnString;
}

function logout() {
	session_start();
	$_SESSION['userid']       = null;
	$_SESSION['logged']       = null;
	$_SESSION['UID']          = null;
	$_SESSION['userFullName'] = null;
	$_SESSION['userLevel']    = null;
}
?>